﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using NLog;
using PersistenceDataLogic;
using PersistenceDataLogic.Core;
using QueryDataLogic;
using QueryDataLogic.Core;

namespace WebAPI_QiSiMealSystem.Controllers
{
    [Route("gbt/[controller]")]
    [ApiController]
    public class SystemSettingController : ControllerBase
    {
        private static Logger logger = LogManager.GetCurrentClassLogger();
        SystemSetting ss = new SystemSetting();
        OperationSystemSetting oss = new OperationSystemSetting();

        // GET: gbt/SystemSetting
        [HttpGet]
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET: gbt/SystemSetting/5
        [HttpGet("SystemSetting/{districtID}", Name = "GetSystemSetting")]
        public async Task<IActionResult> GetSystemSetting(int districtID)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                JObject joResult = new JObject
                {
                    ["Error"] = ""
                };
                try
                {
                    joResult = ss.GetSystemSetting(districtID);
                }
                catch (Exception ex)
                {
                    joResult["Error"] = ex.Message + "\r\n" + ex.StackTrace;
                }
                return Ok(new { root = joResult });
            });
            return task;
        }

        // POST: gbt/SystemSetting
        [HttpPost("ConstraintDishes")]
        public async Task<IActionResult> ConstraintDishes([FromBody] JObject value)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                JObject joResult = new JObject
                {
                    ["Error"] = ""
                };
                try
                {
                    joResult = oss.OptConstraintDishes(value);
                }
                catch (Exception ex)
                {
                    joResult["Error"] = ex.Message + "\r\n" + ex.StackTrace;
                }
                return Ok(new { root = joResult });
            });
            return task;
        }

        // PUT: gbt/SystemSetting/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE: gbt/ApiWithActions/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}
